from django.db import models

# Create your models here.
class SystemSetting(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField("系统名称", max_length=100, null=True,blank=True)
    mount=models.DecimalField("支付金额", max_digits=10, decimal_places=2, null=True,blank=True)
    content = models.TextField(verbose_name='查询内容',null=True,blank=True)
    img=models.ImageField(upload_to='static/img/',null=True,blank=True,verbose_name='logo图片')

    class Meta:
        db_table = 'y_conf'
        verbose_name = '系统设置'
        verbose_name_plural = '系统设置'

    def save(self, *args, **kwargs):
        # 强制只能有一条记录（id=1）
        self.id = 1
        super().save(*args, **kwargs)

    @classmethod
    def get_setting(cls):
        # 快捷获取系统配置（不存在则自动创建）
        obj, created = cls.objects.get_or_create(id=1)
        return obj